package com.dcivision.framework.taglib.utility;

import javax.servlet.jsp.PageContext;

import com.dcivision.framework.GlobalConstant;
import com.dcivision.framework.SessionContainer;
import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;

public class SourceManage {

  public static String getImgSrc(PageContext pageContext,String src,boolean common,boolean customize){
    String contextPath = (String)pageContext.getServletContext().getAttribute(GlobalConstant.CONTEXT_PATH_KEY);
    SessionContainer sessionContainer = (SessionContainer)pageContext.getSession().getAttribute(GlobalConstant.SESSION_CONTAINER_KEY);
    String preference = SystemParameterFactory.getSystemParameter(SystemParameterConstant.PREFERENCE);
    Object tmpLocale = pageContext.getSession().getAttribute(org.apache.struts.Globals.LOCALE_KEY);
    String localeStr = tmpLocale == null ? SystemParameterFactory.getSystemParameter(SystemParameterConstant.LOCALE) : tmpLocale.toString();

    if ((sessionContainer!=null) && (sessionContainer.getUserRecord()!=null)) {
      if (sessionContainer.getUserRecord().getPreference()!=null) {
        preference = sessionContainer.getUserRecord().getPreference().toString();
      }
    }

    if (common) {
      return(contextPath + "/theme/pref" + preference + "/img/common/" + src);
    } else if (customize) {
      return(contextPath + "/theme/pref" + preference + "/customize/" + src);
    } else {
      return(contextPath + "/theme/pref" + preference + "/img/" + localeStr + "/" + src);
    }
  }
}
